package org.yangspring.samples.mvc.daoOracle;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.yangspring.samples.mvc.domainOracle.ProductInfo;

import java.util.List;

/**
 * Created by whyang on 2017/06/22.
 */

@Repository
public class ProductInfoDAOImpl implements ProductInfoDAO {

    private static final Logger logger = LoggerFactory.getLogger(ProductInfoDAO.class);

    @Autowired
    @Qualifier("hibernate5AnnotatedSessionFactoryOracle")
    private SessionFactory sessionFactory;
    public void setSessionFactory(SessionFactory sessionFactory){
        this.sessionFactory = sessionFactory;
    }


    public List<ProductInfo> listProdInfo(){
//        Session session = this.sessionFactory.getCurrentSession();
        Session session = this.sessionFactory.openSession();
        TransactionSynchronizationManager.bindResource(this.sessionFactory, session);

        List<ProductInfo> proInfoList = session.createQuery("from ProductInfo").list();

        for(ProductInfo t : proInfoList){
            logger.info("proInfo List::" + t);
        }
        return proInfoList;
    }

}
